import { AutoComplete } from 'antd';
import * as React from "react";
import PointService from "../../business/point/PointService";

function onSelect(value) {
}

class RuleNameComplete extends React.Component {

  constructor(props) {
    super(props)
    this.pointService = new PointService();
    this.searchRuleRes = this.searchRuleRes.bind(this);
  }
  state = {
    dataSource: [],
  }

  pointService:PointService;

  searchRuleRes(res,isSuccess){
    let ruleName = [];
    if(isSuccess&&res.code=="200"){
      res.data.map((item,index)=>{
        ruleName.push(item.activityName);
      });
      this.setState({
        dataSource: !ruleName ? [] :ruleName,
      });
    }

  }

  handleSearch = (value) => {
    if(!value){
        return;
    }else{
      let token = sessionStorage.getItem('adminLoginToken');
      this.pointService.queryByLikeName(value,{},token,this.searchRuleRes);
    }
  }

  render() {
    const { dataSource } = this.state;
    return (
      <AutoComplete
        dataSource={dataSource}
        style={{ width: 200 }}
        onSelect={onSelect}
        onSearch={this.handleSearch}
        placeholder="输入规则名称"
      />
    );
  }
}
export default RuleNameComplete;
